<include file="Common:header" />
<!-- /. NAV SIDE  -->
<include file="Common:left" />
<!-- /. NAV SIDE  -->
<script type="text/javascript" charset="utf-8" src="__UEDITOR__/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__UEDITOR__/ueditor.all.js"></script>
<script type="text/javascript" src="__UEDITOR__/lang/zh-cn/zh-cn.js"></script>
<div id="page-wrapper">
	<div class="header">
		<h1 class="page-header">
			新闻管理 <small>Welcome {$Think.config.system_tag}</small>
		</h1>
		<ol class="breadcrumb">
			<li><a href="{:U('Index/index')}">首页</a></li>
			<li><a href="{:U('News/newsList')}">新闻列表</a></li>
			<li class="active">添加新闻</li>
			<div style="float:right"><a href="javascript:history.go(-1);">返回</a></div>
		</ol> 
	</div>
	<div id="page-inner">
		<div class="row">
			<div class="col-xs-12">
				<!--Search content-->
				<div class="panel panel-default">
					<div class="panel-body">
						<form class="layui-form" action="" id="postform">
							<input type="hidden" name="id" value="{$info.id}">
                        	<div class="layui-form-item">
                        		<label class="layui-form-label">名称</label>
                        		<div class="layui-input-block">
                        		  <input value="{$info.title}" type="text" name="title" required  lay-verify="required" placeholder="请输入表情名称" autocomplete="off" class="layui-input">
                        		</div>
                        	</div>
							<div class="layui-form-item" style="z-index: 99999;">
								<label class="layui-form-label">分类</label>
								<div class="layui-input-block">
									<select name="tid" lay-verify="required">
										<option value="">请选择</option>
										<notempty name="newsCateList">
											<volist name="newsCateList" id="vo">
												<option value="{$vo.id}" <if condition="$info['tid'] eq $vo['id']">selected</if>>{$vo.name}</option>
												</li>
											</volist>
										</notempty>
									</select>
								</div>
							</div>
                        	<div class="layui-form-item">
                        		<label class="layui-form-label">图片</label>
                        		<div class="layui-input-block">
                        			<div class="layui-upload">
                        			  <button type="button" class="layui-btn" id="test2">上传图片</button>
                        			  <div class="layui-upload-list" id="demo2" data-id="">
                        				<if condition="!empty($info['img_url'])">
                        					<div class="imgcss"><input type="hidden" name="img_url" id="smallimage1" value="{$info.img_url}"><a href="{$info.img_url}" target="_blank"><img src="{$info.img_url}" width="100"></a></div>
                        				</if>
                        			  </div>
                        			  <div id="demoText1">750*750px（必须为正方形）</div>
                        			</div> 
                        		</div>
                        	</div>
                        	<div class="layui-form-item layui-form-text" style="z-index: 1;">
								<label class="layui-form-label">内容</label>
								<div class="layui-input-block">
								  <script type="text/plain" id="myEditor" name="content" style="width:100%;height:240px;">{$info.content}</script>
								</div>
							</div>
							<div class="layui-form-item">
                        		<label class="layui-form-label">序号</label>
                        		<div class="layui-input-block">
                            		<div class="layui-input-inline">
                            		  <input value="{$info.sort}" type="text" name="sort" placeholder="请输入序号" autocomplete="off" class="layui-input">
                            		</div>
                            		<div class="layui-form-mid layui-word-aux">数字越大排序越靠前</div>
                            	</div>
                        	</div>
                        	<div class="layui-form-item">
                        		<label class="layui-form-label">时间</label>
                        		<div class="layui-input-block">
                        		  <input value="{$info.addtime}" type="text" name="addtime" required  lay-verify="required" placeholder="请输入资讯时间" autocomplete="off" class="layui-input" id="addtime_todate">
                        		</div>
                        	</div>
                        	<div class="layui-form-item">
                        		<label class="layui-form-label" style="width:auto">是否启用</label>
                        		<div class="layui-input-block">
                        		  <input type="radio" name="status" value="1" title="是" <if condition="$info.status eq 1">checked</if>>
                        		  <input type="radio" name="status" value="0" title="否" <if condition="$info.status eq 0">checked</if>>
                        		</div>
                        	</div>
							<div class="layui-form-item">
								<div class="layui-input-block">
								  <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
								  <button type="reset" class="layui-btn layui-btn-primary">重置</button>
							    </div>
						    </div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
	<include file="Common:foot" />
	<script>
	//Demo
    var ue = UE.getEditor('myEditor',{zIndex:1});
    layui.use('form', function(){
	  var form = layui.form;
	  layui.use('upload', function(){
    		var $ = layui.jquery
    		,upload = layui.upload;
    		var uploadInst = upload.render({
    			elem: '#test2'
    			,url: "{:U('Common/uploadImage')}"
    			,size:'0'
    			,exts:'jpeg|gif|png|jpg'
    			,multiple: false
    			,method: 'POST'
    			,before: function(obj){
    				//预读本地文件示例，不支持ie8
    				obj.preview(function(index, file, result){
    					$('#demo2').html('<div class="imgcss"><input type="hidden" name="img_url" id="smallimage1"><img src="'+result+'" width="100"></div>'); //文件名
    				});
    			}
    			,done: function(res){
    				//如果上传失败
    				if(res.code==0){
    					return layer.msg(res.value);
    				}else{
    					$('#smallimage1').val(res.value);
    				}
    			}
    			,error: function(){
    				//演示失败状态，并实现重传
    				var demoText = $('#demoText1');
    				demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
    				demoText.find('.demo-reload').on('click', function(){
    					uploadInst.upload();
    				});
    			}
    		});
    	});
	  //监听提交
	  form.on('submit(formDemo)', function(data){
			var cont = data.field;
			$.ajax({
				url:"{:U('News/editNews')}",
				type:'post',
				dataType:'json',
				data:cont,
				success:function(data){
					if(data.code==0){
						layer.alert(data.message);
					}else{
						layer.alert(data.message, function(index){
							//do something
				// 			window.parent.location.reload();
				// 			var index = parent.layer.getFrameIndex(window.name); 
				// 			parent.layer.close(index);
			            	window.location.href="{:U('News/newsList')}";
						});
					}
				}
			});
			//layer.msg(JSON.stringify(data.field));
			return false;
	  });
	});
	</script>
</div>
<include file="Common:footer" />